#include <bits/stdc++.h>
using namespace std;
const int N=105;
struct Stu{
    string name;
    int grade;
    int rank;

    bool operator <=(const Stu& rhs)const{
        return grade<=rhs.grade;
    }
    bool operator >=(const Stu& rhs)const{
        return grade>=rhs.grade;
    }
}stus[N];
int n;
int part_sort(int l,int r){
    Stu &key=stus[r];
    while(l<r){
        while(l<r && stus[l]>=key){
            l++;
        }
        while(l<r && stus[r]<=key){
            r--;
        }
        swap(stus[l],stus[r]);
    }
    swap(stus[l],key);
    return l;
}
void quick_sort(int l,int r){
    if(l>=r){
        return;
    }
    int idx=part_sort(l,r);
    quick_sort(l,idx-1);
    quick_sort(idx+1,r);
}
int main(void){
/*
8
aaaa 56
bbbb 24
cccc 99
dddd 15
eeee 100
ffff 65
gggg 56
hhhh 99
*/
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin >> stus[i].name >> stus[i].grade;
    }
    quick_sort(0,n-1);
    int now=1;
    for(int i=0;i<n;i++){
        stus[i].rank=now;
        if(i+1<n && stus[i].grade!=stus[i+1].grade){
            now++;
        }
    }
    printf("ranked:\n");
    for(int i=0;i<n;i++){
        cout << stus[i].rank <<" " << stus[i].name <<" " << stus[i].grade << endl;
    }
    return 0;
}